package com.newland;

import com.newland.util.DBUtils;
import com.newland.util.MyUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Properties;

/**
 *Description:
 *Version:1.0.0
 *@author shihb
 *@date 2020/3/30 15:40
 */
public class File2Oracle {

  public static void main(String[] args) throws SQLException {
    if(args.length>0){
      MyUtils.loadConfigFile(args[0]);
    }else {
      MyUtils.loadConfigFile("config.properties");
    }
    BufferedReader br=null;
    try {
      Properties prop= MyUtils.getConfig();
      File resultFile=new File(prop.getProperty("resultFile"));
      if(!resultFile.exists()){
        return;
      }
      ArrayList<String> sqlList= new ArrayList<String>();
      // 从文件读sql执行
      br=new BufferedReader(new InputStreamReader(new FileInputStream(resultFile),"UTF-8"));
      String sql=null;
      while((sql=br.readLine())!=null){
        sqlList.add(sql);
      }
      DBUtils.batchExecuteSql(sqlList);

    }catch (Exception e){
      e.printStackTrace();
    }finally{
      try {
        if( br!=null){
          br.close();
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
}
